/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/goodsService.ts" />
/// <reference path="../src/tms.ts" />

describe('getGoodsList',() => {
    var injector:ng.auto.IInjectorService;
    var service:IGoodsService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<IGoodsService>('goodsService');
    });

    //常规无条件获取
    it('get goods list normal',(done) => {
        service.getList(null, null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取企业公司编号包含4的货物列表
    it('get goods list by enterpriseid \'4\'',(done) => {
        service.getList('4',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('4|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取货物名称包含玫瑰 的货物列表
    it('get goods list by name \'玫瑰\'',(done) => {
        service.getList(null,'玫瑰',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|玫瑰||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取货物类别编号包含 002 的货物列表
    it('get goods list by goodtypeid \'002\' ',(done) => {
        service.getList(null,null,'002',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||002|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 企业公司编号包含4, 货物名称包含 玫瑰, 货物类别编号包含2 的货物列表
    it('get goods list by enterpriseid \'4\' and name \'玫瑰\' and goodtypeid \'2\' ',(done) => {
        service.getList('4','玫瑰','2',0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('4|玫瑰|2|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });


    //获取货物详情
    it('get detail',(done)=>{
        service.getDetail('1').then((res)=>{
            expect(res.data.enterpriseCompanyId).toBe("4");
            expect(res.data.name).toBe("detail");
            expect(res.data.productCode).toBe("2");
            expect(res.data.categoryId).toBe("2");
            expect(res.data.auxiliaryTool).toBe("刀");
            expect(res.data.packageMethod).toBe("袋装");
            expect(res.data.gwRate).toBe(1);
            expect(res.data.length).toBe(30);
            expect(res.data.width).toBe(30);
            expect(res.data.height).toBe(10);
            expect(res.data.volume).toBe("50");
            expect(res.data.weight).toBe(10);
            expect(res.data.weightUnit).toBe("千克");
            expect(res.data.goodNorms).toBe("30*30");
            expect(res.data.compensation).toBe("退款");
            expect(res.data.remarks).toBe("备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加货物
    it('add goods',(done)=>{
        service.add('2','玫瑰花','001','3','工具', '袋装',1,30,30,10,'50',10,'千克','30*30','退款','备注').then((res)=>{
            expect(res.data.extData).toBe("2|玫瑰花|001|3|工具|袋装|1|30|30|10|50|10|千克|30*30|退款|备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });


    //编辑货物
    it('edit goods',(done)=>{
        service.edit('1','2','玫瑰花','001','3','工具', '袋装',1,30,30,10,'50',10,'千克','30*30','退款','备注').then((res)=>{
            expect(res.data.extData).toBe("1|2|玫瑰花|001|3|工具|袋装|1|30|30|10|50|10|千克|30*30|退款|备注");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除货物
    it('delete goods',(done)=>{
        service.delete('2').then((res)=>{
            expect(res.data.extData).toBe("2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });


});